package com.ruoyi.web.controller.user;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/api")
public class UserController {
    @Autowired
    private UserService userLoginService;
    /**
     * 登录操作
     * */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody User user) {
        String message = userLoginService.login(user);
        if(message=="登录成功"){
            return AjaxResult.success();
        }
        else{
            return AjaxResult.error();
        }

    }
    @PostMapping("/register")
    public AjaxResult register(@RequestBody User user) {
        String message = userLoginService.register(user);
        if ("注册成功".equals(message)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error(message); // 把错误信息也返回
        }
    }
}
